export default {
  created() {
    this.bindResizeHandler();
  },
  mounted() {
    this.resizeHandler();
  },
  beforeDestroy() {
    this.unbindResizeHandler();
    this.isShow = false
  },
  props: {
    viewWidth: {
      type: Number,
      default: 0,
    },
    viewHeight: {
      type: Number,
      default: 0,
    },
    real: {
      type: Object,
      default: () => []
    }
  },
  data() {
    return {
      digital: {},
      analog: {},
      isShow: false
    }
  },
  computed: {
    // 两百万运行
    runSignal() {
      return function (data) {
        if (data.run == 1 && data.warn == 0) {
          return "#29FB29"
        } else if (data.run == 0 && data.warn == 0) {
          return "#EBEBEB"
        } else if (data.warn == 1) {
          return "#E54648"
        } else {
          return "#EBEBEB"
        }
      }
    }
  },
  methods: {
    /**
     * 重组数据
     */
    reorganizeData(data) {
      console.log(data, 665544)
      this.digital = data.digital
      this.analog = data.analog
      if (this.digital && this.analog) {
        this.isShow = true
      }
    },
    resizeHandler() {
      // const { $refs } = this;
      // const svg = $refs.svg;

      //const { clientWidth, clientHeight } = svg;// eslint-disable-line no-unused-vars
    },
    bindResizeHandler() {
      window.addEventListener("resize", this.resizeHandler, false);
    },
    unbindResizeHandler() {
      window.removeEventListener("resize", this.resizeHandler);
    },
  },
  watch: {
    real: {
      handler(newVal, oldVal) { // eslint-disable-line no-unused-vars
        if (newVal) {
          console.log(123)
          this.reorganizeData(newVal)
        }
      },
      deep: true,
      immediate: true,
    },
  }
}